<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>承接查验阶段</title>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="js/bootstrap2/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="js/webuploader-0.1.5/webuploader.css" />
<link rel="stylesheet" href="css/vivo.css">
<link rel="stylesheet" href="css/common.css">


<script src="js/jquery-1.11.1.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="js/webuploader-0.1.5/webuploader.js"></script>
<!-- 图片放大 -->
<script src="js/postbird-img-glass/postbird-img-glass.js"></script>
<script type="text/javascript" src="js/layui-v2.1.5/layui/layui.all.js"></script>

<script type="text/javascript" src="js/form.js"></script>
<script src="js/sharefunction.js"></script>

<style type="text/css">
.tdWidth {
	width: 100px;
}
</style>
</head>
<body>
	<div>
		<form id="continueForm" action="project/approval/addContinueStage" method="post" >
			<!-- 文件文本域 -->
			<input type="hidden" id="fileHidden" >
			<div class="panel panel-default">
				<div class="panel-heading">
					<h5 class="panel-title">承接查验阶段</h5>
				</div>
				<div class="panel-body">
					<table cellpadding="10" cellspacing="5" class="mytable">
						<tr>
							<td width="100" align="right">承接查验时间</td>
							<td width="260">
								<input name="checkDate" class="Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="<fmt:formatDate value="${requestScope.checkStage.checkDate }" pattern="yyyy-MM-dd" />" />
								<span style="color: red">*</span>
							</td>
							<td width="100" align="right">项目名称</td>
							<td>
								<input name="checkName"  value="${requestScope.checkStage.checkName }"  />
							</td>
						</tr>
						<tr>
							<td  align="right">资料</td>
							<td width="100">
								<input name="checkScope" value="${requestScope.checkStage.checkScope }" />
							</td>
							<td>
								<div id="filePicker_up" style="display:none;">上传</div>
							</td>
						</tr>
						<tr>
							<td colspan="3">
								<div id="list_up"></div>
							</td>
						</tr>
					</table>
					
				</div>
			</div>
			<input value="${requestScope.checkStage.id }" hidden="hidden" id = "entityId_id" name="entityId_id"/>
				<!-- 修改时添加变更说明 -->
		<div style="margin:10px;" hidden="hidden" id="changeRemark">
			变更说明<textarea rows="3" name="changeRemark"style="width:70%"></textarea><span style="color:red;">*</span>
		</div>
		<div style="width:100%;text-align:center; padding-top:0px">
			<c:choose>
				<c:when test="${empty requestScope.checkStage }">
					<button class="btn btn-danger radius my-btn"
						onclick="saveCheck(0)" type="button">提交</button>
					<button class="btn btn-danger radius my-btn"
						onclick="saveCheck(1)" type="button">保 存</button>
					<a class="btn btn-default radius" onClick="resetForms('checkStage');">
						重置 </a>
					<br />
				</c:when>
				<c:otherwise>
					<shiro:hasPermission name="permission:edit">
						<%-- <c:if test="${requestScope.pendingStatus }"> --%><!-- 如果有待审批，隐藏操作按钮 -->
							<button id="modifyBtn" class="btn btn-danger radius my-btn"
								onclick="saveCheck(3)" type="button">启用编辑</button>
							<button class="btn btn-danger radius my-btn hidbtn"
								onclick="saveCheck(2)" type="button">提交审批</button>
							<a class="btn btn-default radius hidbtn" onClick="resetForms('checkStage');">
								重置 </a>
						<%-- </c:if>	 --%>
					</shiro:hasPermission> 
				</c:otherwise>
			</c:choose>
		</div>
		</form>
	</div>
</body>
<script type="text/javascript">
	$(function() {
		//如果已经保存过了，则开启只读状态
		<c:if test="${not empty requestScope.checkStage }">
			$("#continueForm").find("input,textarea").attr("readonly",true);
			$("#continueForm .Wdate").attr("disabled",true);
		</c:if>
		//初始化上传附件
		initWebUpload("filePicker_up", "list_up", "资料","fileHidden",fileSuccess, fileErr);
		//初始化表单
		mySubmit("continueForm", initContinue, successContinue);
		getFiles();
		//上传按钮添加默认宽高
		$("div[id^='filePicker_'] div").css({
				"width" : "60px",
				"height" : "28px"
			});
		var id = '${requestScope.checkStage.id}';
		if(id == ""){
  			//上传按钮水平排列
			$("div[id^='filePicker_']").css({"display":"inline-block","vertical-align":"bottom"});
			$("#continueForm .uploadcancel").show();
  		}
	});
	//上传成功 初始化图片放大
	function fileSuccess() {
		PostbirdImgGlass.init({
			domSelector : "#list_up img",
			animation : true,
			myDocument : top
		});
		console.log($("#fileHidden").val(),2);
	}
	function fileErr() {
		alert("图片上传失败");
	}
	//封装上传参数
	function initContinue(){
		var fileData=$("#fileHidden").val();//附件数据
		var checkDate = $("#continueForm input[name='checkDate']").val();//时间
		var checkScope = $("#continueForm input[name='checkScope']").val();//资料
		var checkName = $("#continueForm input[name='checkName']").val();//项目名称
		var changeRemark = $("#continueForm [name='changeRemark']").val();//变更意见
		var checkId = $("#continueForm input[name='entityId_id']").val();
		var i = layer.load(2);
		if(checkId != "" && changeRemark==""){
			layer.alert("变更说明不能为空");
			layer.close(i);
			return null;
		}else{
			return {
				id:checkId,
				fileData:fileData,
				checkName:checkName,
				fkProjectApproval:$("#fkPa",parent.document).val(),
				checkDate:checkDate,
				checkScope:checkScope,
				changeRemark:changeRemark,
				opt:checkOpt,
				rFileList:rFileList.toString()
			};
		}
	}
	//提交回调
	function successContinue(data){
		if(data){
			layer.alert("保存成功", {
	       		offset:'20%',
	       		shade:[0.1,'#fff']
			}, function() {
				parent.location.reload();
	
			});
		}else{
			alert("保存失败", {icon: 7});
			layer.closeAll();
		}
	}
	
	//展示附件  
	function getFiles() {
	  getFileListByFlag($("#continueForm #entityId_id").val(), "资料", 1,"#list_up", setRFL, imgPlus);
	}
	 function imgPlus(data) {
		$("#continueForm .uploadcancel").css("display", "none");
		$.each(data, function(i, v) {
			//图片放大
			PostbirdImgGlass.init({
				domSelector : "#" + v.id + " img",
				animation : true,
				myDocument : window.parent.parent.parent
			});
		});
	}
	var rFileList = new Array(); //
	//设置待删除附件的值到集合中
	function setRFL(id, _this) {
		layer.confirm('删除该图片？', {
			title : '警告',
			icon : 0,
			shade : [ 0.1, '#fff' ]
		}, function() {
			rFileList.push(id);
			//rFileList=id+","+rFileList
			//删除指定缩略图
			$("#" + id).remove();
			layer.close(layer.index);
		});
	}
	//启用编辑
	var checkOpt;//记录编辑还是新增的状态
	function saveCheck(val){
		checkOpt = val;
		if("3" == val){//启用编辑状态
			var approvalCount = ${approvalCount};
			if(approvalCount == 0 ){
				//解除锁定状态
				var index=layer.confirm('确定开启编辑状态？', {
				 	offset:'20%',
					shade:0
				}, function(){
				  //去除只读开启按钮编辑
				  //上传按钮水平排列
				   $("div[id^='filePicker_']").css({"display":"inline-block","vertical-align":"bottom"});
				   $("#continueForm #changeRemark").show();
				   $("#continueForm").find("input,textarea").attr("readonly",false);
				   $("#continueForm .Wdate").attr("disabled",false);
				   $("#continueForm #modifyBtn").remove();
				   $("#continueForm .hidbtn").removeClass("hidbtn");
				   $("#continueForm .uploadcancel").show();
				   layer.close(index);
				});
			}else{
				layer.msg("此条数据已提交过审批，不能重复提交");
			}
		}else{
			$("#continueForm").submit();
		}
	}
	
</script>
</html>